#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<unordered_map>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define lowbit(x) x&(-x)
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef int LL;
char str[maxn];
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
unordered_map<char,LL>map1;
queue<LL>que[5];
LL tree[maxn],siz[10];
long long mx=-1;
char p[6]={"ANTO"};
LL pos[maxn];
inline void add(LL x,LL d){
     while(x<maxn){
        tree[x]+=d;
        x+=lowbit(x);
     }
}
inline long long getsum(LL x){
    long long sum=0;
    while(x>0){
       sum+=tree[x];
       x-=lowbit(x);
    }return sum;
}
inline void init(){
    for(LL i=1;i<=4;i++) while(!que[i].empty()) que[i].pop();
    memset(siz,0,sizeof(siz));
}
inline long long solve(LL n){
     for(LL i=1;i<=n;i++) tree[i]=0;
     for(LL i=1;i<=n;i++) pos[i]=0;
     queue<LL>q[5];
     for(LL i=1;i<=4;i++) q[i]=que[i];
     LL tot=0;
     for(LL i=0;i<4;i++){
        for(LL j=1;j<=siz[map1[p[i]]];j++){
            pos[++tot]=q[map1[p[i]]].front();
            q[map1[p[i]]].pop();
        }
     }
     long long res=0;
     for(LL i=1;i<=tot;i++){
         add(pos[i],1);
         res+=(i-getsum(pos[i]));
     }
     return res;
}
int main(void){
   	LL t;t=read();
   	map1['A']=1;map1['N']=2;map1['T']=3;map1['O']=4;
   	while(t--){
        scanf("%s",str+1);LL n=strlen(str+1);
        LL tot=0;
        init();
        for(LL i=1;i<=n;i++) {que[map1[str[i]]].push(++tot);siz[map1[str[i]]]++;}
        mx=-1;
        string ans="";
        do{
            long long res=solve(n);
            if(res>mx){
                mx=res;
                ans="";
                for(LL i=0;i<4;i++) ans+=p[i];
            }
        }while(next_permutation(p,p+4));

        for(int i=0;i<ans.size();i++){
            for(LL j=1;j<=siz[map1[ans[i]]];j++){
                printf("%c",ans[i]);
            }
        }
        printf("\n");
   	}
   	return 0;
}
